import React from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { addCar } from '../store/slice/carSlice'

export default function GoodsList() {
    const dispatch = useDispatch()
    const {goods} = useSelector(state => state.goods)
  return (
    <div>
      <h3>商品列表</h3>
      <ul>
        {goods.map(good => (
            <li key={good.id}>
                <h4>商品名称： {good.gname}</h4>
                <p>商品价格： {good.gprice}</p>
                <p><button onClick={() => {
                    dispatch(addCar(good))
                }}>加入购物车</button></p>
            </li>
        ))}
      
      </ul>

    </div>
  )
}
